package com.sskj.common.util;

import com.sskj.common.R;
import com.sskj.common.base.App;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by lv on 18-6-4.
 */

public class TimeFormatUtil {
    public static String FORMAT_A = "yyyy.MM.dd HH:mm";
    public static String FORMAT_B = "yyyy-MM-dd";
    public static String FORMAT_C = "HH:mm dd/MM";
    public static String FORMAT_D = "mm分ss秒";
    public static String FORMAT_E = "yyyy-MM-dd HH:mm:ss";
    public static String FORMAT_F = "yyyy-MM-dd HH:mm";
    public static String FORMAT_G = "MM-dd HH:mm";
    public static String FORMAT_H = "HH:mm:ss";
    public static String FORMAT_I = "yyyy年MM月";
    public static String FORMAT_J = "yyyy/MM/dd HH:mm:ss";
    public static String FORMAT_K = "yyyy-MM";
    public static String FORMAT_L = "yyyy/MM/dd HH:mm";
    public static String FORMAT_M = "DD天HH小时mm分ss秒";


    public static SimpleDateFormat SF_FORMAT_A = new SimpleDateFormat(FORMAT_A);
    public static SimpleDateFormat SF_FORMAT_B = new SimpleDateFormat(FORMAT_B);
    public static SimpleDateFormat SF_FORMAT_C = new SimpleDateFormat(FORMAT_C);
    public static SimpleDateFormat SF_FORMAT_D = new SimpleDateFormat(FORMAT_D);
    public static SimpleDateFormat SF_FORMAT_E = new SimpleDateFormat(FORMAT_E);
    public static SimpleDateFormat SF_FORMAT_F = new SimpleDateFormat(FORMAT_F);
    public static SimpleDateFormat SF_FORMAT_G = new SimpleDateFormat(FORMAT_G);
    public static SimpleDateFormat SF_FORMAT_H = new SimpleDateFormat(FORMAT_H);
    public static SimpleDateFormat SF_FORMAT_I = new SimpleDateFormat(FORMAT_I);
    public static SimpleDateFormat SF_FORMAT_J = new SimpleDateFormat(FORMAT_J);
    public static SimpleDateFormat SF_FORMAT_K = new SimpleDateFormat(FORMAT_K);
    public static SimpleDateFormat SF_FORMAT_L = new SimpleDateFormat(FORMAT_L);
    public static SimpleDateFormat SF_FORMAT_M = new SimpleDateFormat(FORMAT_M);


    public static String formatA(Long time) {
        return SF_FORMAT_A.format(new Date(time));
    }

    public static String formatB(Long time) {
        return SF_FORMAT_B.format(new Date(time));
    }
    public static String formatE(Long time) {
        return SF_FORMAT_E.format(new Date(time));
    }
    public static String formatH(Long time) {
        return SF_FORMAT_H.format(new Date(time));
    }

    public static String formatSix2Five(String time) {
        return time.substring(0, time.length() - 3);
    }

    //将该种时间格式的时间转为时间戳  yyyy-MM-dd HH:mm:ss
    public static String parseLongE(String time) {
        try {
            return (SF_FORMAT_E.parse(time).getTime() / 1000) + "";
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String parseLongB(String time) {
        try {
            return (SF_FORMAT_B.parse(time).getTime()) + "";
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }


    /**
     * @param time
     * @return
     */
    public static String parseTime(Long time) {
        if (time < 60) {
            return time + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil18);
        }
        if (time < 60 * 60) {
            long minute = time / 60;
            long second = time % 60;
            return minute + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil19) + second + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil18);
        }
        if (time < 24 * 60 * 60) {
            long hour = time / (60 * 60);
            long minute = (time % (60 * 60)) / 60;
            long second = time % 60;
            return hour + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil21) + minute + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil19) + second + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil18);
        }
        if (time > 24 * 60 * 60) {
            long day = time / (60 * 60 * 24);

            long hour = time % (60 * 60 * 24) / (60 * 60);
            long minute = (time % (60 * 60)) / 60;
            long second = time % 60;
            return day + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil24) + hour + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil21) + minute + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil19) + second + App.INSTANCE.getString(R.string.commonJavaTimeFormatUtil18);
        }
        return "";
    }
}
